define([
    'angular',
    'angular-cookies',
    'core/factories/table',
    'core/factories/dialog'
], function(angular) {
    var factory = angular.module('app.factory', ['ngCookies', 'app.factory.table', 'app.factory.dialog']);

    // AuthFactory
    factory.factory('AuthFactory', ['$cookieStore', function($cookieStore) {
        var authCookieName = "AUTHENTICATION";
        var authParameters = {
            user: '',
            target: '',
            logout: false,
            authenticated: false
        };

        function getAuthParameters() {
            var authCookieInfo = $cookieStore.get(authCookieName);
            if (angular.isDefined(authCookieInfo)) {
                angular.extend(authParameters, authCookieInfo);
            }
            return authParameters;
        }

        return {
            getParameters: function() {
                return getAuthParameters();
            },
            setParameters: function(parameters) {
                angular.extend(authParameters, parameters);
                $cookieStore.put(authCookieName, authParameters);
            },
            setAuthenticated: function(authenticated) {
                authParameters.authenticated = authenticated;
                $cookieStore.put(authCookieName, authParameters);
            },
            isAuthenticated: function() {
                return getAuthParameters().authenticated;
            }
        };
    }]);

    return factory;
});
